#include "login.h"
#include "ui_login.h"

login::login(QWidget *parent) : QWidget(parent),
                                ui(new Ui::login)
{

    resize(QT_WIDTH, QT_HEIGHT);
    setStyleSheet("background-color: #FFFFFF;");

    // 

    QLineEdit *username = new QLineEdit(this);
    username->setFixedSize(300, 40);
    username->setPlaceholderText("请输入用户名");
    int x = (width() - username->width()) / 2;
    int y = (height() / 2) - 110;
    username->move(x, y);

    QLabel *label = new QLabel(this);
    label->setText("QT微信");
    label->setFont(QFont("Arial", 16, QFont::Bold));
    label->setAlignment(Qt::AlignCenter);
    label->setStyleSheet("color: #1dad28;");
    label->setGeometry(x + 115, 110, 70, 30);

    QLineEdit *password = new QLineEdit(this);
    password->setEchoMode(QLineEdit::Password);
    password->setFixedSize(300, 40);
    password->setPlaceholderText("请输入密码");
    int y2 = y + 60;
    password->move(x, y2);

    QPushButton *loginButton = new QPushButton("登录", this);
    loginButton->setStyleSheet("QPushButton{background-color: #1dad28; color: #FFFFFF; border-radius: 5px;}"
                               "QPushButton:hover{background-color: #1dad28; color: #FFFFFF; border-radius: 5px;}"
                               "QPushButton:pressed{background-color: #1dad28; color:#FFFFFF; border-radius: 5px;}");
    loginButton->setFixedSize(300, 40);
    int y3 = y2 + 60;
    loginButton->move(x, y3);
    connect(loginButton, &QPushButton::clicked, [=]()
            {
        // 判断账号为admin密码为admin123
        if (username->text() =="admin"&& password->text()=="admin123")
        {
            qDebug() << "用户名：" << username->text() << "密码：" << password->text();
            QMessageBox::information(this, "登录成功", "用户名：" + username->text() + "\n密码：" + password->text());
            // 登录成功发送信号
            emit loginSuccess();
        }else{
            QMessageBox::warning(this, "错误", "请输入正确的用户名和密码");
            return;
        } });

    QPushButton *leftButton = new QPushButton("注册", this);
    leftButton->setStyleSheet("QPushButton{font-size:16px; font-weight:700; background-color: transparent; color: #1dad28; border: none;}"
                              "QPushButton:hover{background-color: transparent; color: #1dad28; border: none;}"
                              "QPushButton:pressed{background-color: transparent; color: #1dad28; border: none;}");
    leftButton->move(x + 2, y3 + 56);
    connect(leftButton, SIGNAL(clicked()), this, SLOT(registerFn()));

    QPushButton *rightButton = new QPushButton("取消", this);
    rightButton->setStyleSheet("QPushButton{font-size:16px; font-weight:700; background-color: transparent; color: #1dad28; border: none;}"
                               "QPushButton:hover{background-color: transparent; color: #1dad28; border: none;}"
                               "QPushButton:pressed{background-color: transparent; color: #1dad28; border: none;}");
    rightButton->move(x + 260, y3 + 56);
    connect(rightButton, &QPushButton::clicked, [=]()
            {
        qDebug() << "取消";
        close(); });
}
login::~login()
{
    delete ui;
}
// 注册槽函数
void login::registerFn(){
    qDebug() << "注册槽调用函数" <<endl;
    emit toRegister();
    // QMessageBox::information(this, "注册", "注册功能开发中...");
}